package com.bjxst;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

/**字符缓冲流，实现文本文件的拷贝 */
public class FileCopyTools3 {
    public static void main(String[] args) {
        copyFile("d:/b.txt","d:/qq.txt");
    }
    //基于字符流缓冲实现文件拷贝
    public static void copyFile(String src,String des){
        BufferedReader br = null;
        BufferedWriter bw = null;
        try{
            br = new BufferedReader(new FileReader(src));
            bw = new BufferedWriter(new FileWriter(des));
            String temp = "";
            while ((temp = br.readLine()) != null){
                bw.write(temp);
                //读完一行后换行
                bw.newLine();
            }
            bw.flush();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try{
                //关闭不分顺序
                if(br != null){
                    br.close();
                }
                if(bw != null){
                    bw.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
